/* GUI CONVERTED from rcabssad.p (converter v1.75) Tue Apr 10 12:03:12 2001 */
/* rcabssad.p - PROGRAM TO ADD abss_det RECORDS FOR SEQUENCE SCHEDULES        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.10 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 9.1            CREATED: 05/24/99   BY: *N003* Patrick Rowan      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 05/12/00   BY: *N09X* Antony Babu        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* $Revision: 1.10 $    BY: Jean Miller    DATE: 03/22/01 ECO: *P008*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: This program creates links between the sequence detail records
              (rcsd_det) and the shipper records (abs_mstr).  The abss_det
              records are created one per sequence and shipper combination.

 Notes:
 ============================================================================
 !*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter abs_recid as recid no-undo.
define input parameter rcs_recid as recid no-undo.
define input parameter sod_recid as recid no-undo.
define output parameter abss_recid as recid no-undo.
define input-output parameter total_seq_qty like abss_qty no-undo.

define shared variable cust_job like rcsd_cust_job no-undo.

define variable rcsd_recid as recid.
define variable correct-yn like mfc_logical no-undo.
define variable frametitle as character no-undo.
define variable shipid like abs_id no-undo.
define variable cust_seq like rcsd_cust_seq no-undo.
define variable cust_ref like rcsd_cust_ref no-undo.
define variable dock like rcsd_dock no-undo.
define variable line_feed like rcsd_line_feed no-undo.
define variable sched_date like rcsd_date no-undo.
define variable sched_time like rcsd_time no-undo.
define variable l_line like rcsd_line no-undo.


/* FRAME D: UPDATE FRAME */
FORM /*GUI*/ 
   cust_job            colon 31
   cust_seq            colon 31
   cust_ref            colon 31
   dock                colon 31
   line_feed           colon 31
   sched_date          colon 31
   sched_time          colon 50
   skip (1)
   rcsd_discr_qty      colon 31
   pt_um               colon 50
   rcsd_status         colon 31
   rcsd_cust_build_date   colon 31
with down frame d overlay column 3 row 8 side-labels
   width 70 title color normal frametitle THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame d:handle).

/* TRIGGER */
on leave of cust_job in frame d do:

   /* MAKE cust_job AVAILABLE FOR F2-HELP ON cust_seq */
   cust_job = input frame d cust_job.

        
   do on error undo, leave:
   run q-leave in global-drop-down-utilities.
   end.
   run q-set-window-recid in global-drop-down-utilities.
   if return-value = "error" then return no-apply.   

end.

/* INITIALIZAION */
assign
   cust_job = ""
   cust_seq = ""
   cust_ref = ""
   dock = ""
   line_feed = ""
   sched_date = ?
   sched_time = ""
   .

for first rcs_mstr
where recid(rcs_mstr) = rcs_recid no-lock:
end.

for first abs_mstr
where recid(abs_mstr) = abs_recid no-lock:
end.

for first sod_det
where recid(sod_det) = sod_recid no-lock:
end.

run get_shipper
   (input abs_id,
    input abs_shipfrom,
    output shipid).

frametitle =   getFrameTitle("ADD_SEQUENCES",19) + "- " +
               getTermLabel("ORDER_QUANTITY",20) + ": " +
               string(abs_qty) + " " +
               substring(abs__qad02,1,2) + " ".

add-loop:
repeat transaction on error undo, retry with frame d:
/*GUI*/ if global-beam-me-up then undo, leave.


   /*TOTAL QUANTITY ENTERED */
   {pxmsg.i &MSGNUM=2971 &ERRORLEVEL=1 &MSGARG1=total_seq_qty}

   prompt-for
      cust_job
      cust_seq
      cust_ref
      dock
      line_feed
   with frame d editing:

      /* FIND NEXT/PREVIOUS RECORD */
      if frame-field = "cust_job" then do:
         {mfnp05.i rcsd_det rcsd_index4
            "rcsd_shipfrom        = rcs_shipfrom  and
             rcsd_shipto       = rcs_shipto    and
             rcsd_rlse_id      = rcs_rlse_id   and
             rcsd_picked       = no            and
             rcsd_x_referenced = no            and
             rcsd_delete       = no            and
             rcsd_order        = sod_nbr       and
             rcsd_line         = sod_line      and
             rcsd_part         = abs_item"
            rcsd_cust_job "input frame d cust_job"}

         if recno <> ? then do:

            for first pt_mstr
            where pt_part = rcsd_part
            no-lock: end.

            display
               rcsd_cust_job   @ cust_job
               rcsd_cust_seq   @ cust_seq
               rcsd_cust_ref   @ cust_ref
               rcsd_dock       @ dock
               rcsd_line_feed  @ line_feed
               rcsd_date       @ sched_date
               rcsd_time       @ sched_time
               rcsd_discr_qty
               pt_um               when (available pt_mstr)
               rcsd_status
               rcsd_cust_build_date
            with frame d.

         end. /* if recno */
      end. /* if frame-field = "abss_cust_job" */
      else
         if frame-field = "cust_seq" then do:
         {mfnp06.i rcsd_det rcsd_index4
            "rcsd_shipfrom        = rcs_shipfrom  and
             rcsd_shipto       = rcs_shipto    and
             rcsd_rlse_id      = rcs_rlse_id   and
             rcsd_picked       = no            and
             rcsd_x_referenced = no            and
             rcsd_delete       = no            and
             rcsd_order        = sod_nbr       and
             rcsd_line         = sod_line      and
             rcsd_part         = abs_item"
            rcsd_cust_job "input frame d cust_job"
            rcsd_cust_seq "input frame d cust_seq"}

         if recno <> ? then do:

            for first pt_mstr
            where pt_part = rcsd_part
            no-lock: end.

            display
               rcsd_cust_job   @ cust_job
               rcsd_cust_seq   @ cust_seq
               rcsd_cust_ref   @ cust_ref
               rcsd_dock       @ dock
               rcsd_line_feed  @ line_feed
               rcsd_date       @ sched_date
               rcsd_time       @ sched_time
               rcsd_discr_qty
               pt_um               when (available pt_mstr)
               rcsd_status
               rcsd_cust_build_date
            with frame d.
         end. /* if recno */
      end.
      else do:
         readkey.
         apply lastkey.
         status input.
      end.

   end. /* prompt-for abss_cust_job */

   prompt-for
      sched_date
      sched_time
   with frame d.

   /* VALIDATE */
   for first rcsd_det where
         rcsd_shipfrom   = rcs_shipfrom  and
         rcsd_shipto     = rcs_shipto    and
         rcsd_rlse_id    = rcs_rlse_id   and
         rcsd_order      = sod_nbr       and
         rcsd_line       = sod_line      and
         rcsd_part       = abs_item      and
         rcsd_cust_job   = input frame d cust_job    and
         rcsd_cust_seq   = input frame d cust_seq    and
         rcsd_cust_ref   = input frame d cust_ref    and
         rcsd_dock       = input frame d dock        and
         rcsd_line_feed  = input frame d line_feed   and
         rcsd_date       = input frame d sched_date  and
         rcsd_time       = input frame d sched_time
   no-lock: end.

   if not available (rcsd_det) then do:
      {pxmsg.i &MSGNUM=2818 &ERRORLEVEL=3} /* INVALID SEQUENCE */
      undo, retry.
   end.
   else do:
      if rcsd_picked or rcsd_x_referenced then do:
         /* SEQUENCE ALREADY PICKED */
         {pxmsg.i &MSGNUM=2983 &ERRORLEVEL=3}
         undo, retry.
      end.
      else do:
         if rcsd_order <> sod_nbr or
            rcsd_line  <> sod_line then do:
            /* INVALID SEQUENCE FOR THIS ORDER AND LINE */
            {pxmsg.i &MSGNUM=2984 &ERRORLEVEL=3}
            undo, retry.
         end.
         else do:
            if rcsd_deleted then do:
               /* INVALID SEQUENCE. RECORD MARKED AS DELETED */
               {pxmsg.i &MSGNUM=3316 &ERRORLEVEL=3}
               undo, retry.
            end.
         end.  /* else do */
      end.
      rcsd_recid = recid(rcsd_det).
   end.

   for first abss_det
   where abss_abs_id     = abs_id        and
         abss_shipfrom   = abs_shipfrom  and
         abss_shipto     = rcs_shipto    and
         abss_rlse_id    = rcs_rlse_id   and
         abss_order      = sod_nbr       and
         abss_line       = sod_line      and
         abss_part       = abs_item      and
         abss_cust_job   = input frame d cust_job   and
         abss_cust_seq   = input frame d cust_seq   and
         abss_cust_ref   = input frame d cust_ref   and
         abss_dock       = input frame d dock       and
         abss_line_feed  = input frame d line_feed  and
         abss_date       = input frame d sched_date and
         abss_time       = input frame d sched_time
   exclusive-lock: end.

   if available (abss_det) then do:

      /* SEQUENCE ALREADY PICKED */
      {pxmsg.i &MSGNUM=2983 &ERRORLEVEL=3}
      undo, retry.

   end.
   else do:

      /* VALIDATE AGAINST THE SEQUENCE SCHEDULE */
      for first pt_mstr
      where pt_part = rcsd_part
      no-lock: end.

      /* DISPLAY NEW RECORD */
      display
         rcsd_cust_job   @ cust_job
         rcsd_cust_seq   @ cust_seq
         rcsd_cust_ref   @ cust_ref
         rcsd_dock       @ dock
         rcsd_line_feed  @ line_feed
         rcsd_date       @ sched_date
         rcsd_time       @ sched_time
         rcsd_discr_qty
         pt_um               when (available pt_mstr)
         rcsd_status
         rcsd_cust_build_date
      with frame d.

      /* IS THIS CORRECT ? */
      correct-yn = yes.
      {pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=correct-yn
               &CONFIRM-TYPE='LOGICAL'}

      if correct-yn then do:

         /* ADD NEW RECORD */
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
         create abss_det.
         assign
            abss_abs_id     = abs_id
            abss_shipfrom   = abs_shipfrom
            abss_shipto     = rcs_shipto
            abss_rlse_id    = rcs_rlse_id
            abss_cust_job   = input frame d cust_job
            abss_cust_seq   = input frame d cust_seq
            abss_part       = rcsd_part
            abss_qty        = rcsd_discr_qty
            abss_date       = rcsd_date
            abss_time       = rcsd_time
            abss_cust_ref   = input frame d cust_ref
            abss_dock       = input frame d dock
            abss_line_feed  = input frame d line_feed
            abss_ship_id    = shipid
            abss_order      = rcsd_order
            abss_line       = rcsd_line
            abss_status     = rcsd_status
            abss_mod_userid = global_userid
            abss_mod_date   = today
            abss_mod_pgm    = program-name(1)
            total_seq_qty   =
            total_seq_qty + rcsd_discr_qty.
         abss_recid      = recid(abss_det).

         if recid(abss_det) = -1 then .

         for first rcsd_det
         where recid(rcsd_det) = rcsd_recid
         exclusive-lock: end.

         assign
            rcsd_picked     = yes
            rcsd_mod_userid = global_userid
            rcsd_mod_date   = today
            rcsd_mod_pgm    = program-name(1).

         clear frame d.

      end.  /* if correct-yn */

   end.  /* if not available (abss_det) */

end.  /* END OF add-loop */

clear frame d.
hide frame d.

/* --- INTERNAL PROCEDURES --- */

PROCEDURE get_shipper:
/*--------------------------------------------------------------------
  Purpose:
  Parameters:
  Notes:
---------------------------------------------------------------------*/
   define input  parameter in_abs_id like abs_id no-undo.
   define input  parameter in_shipfrom like abs_id no-undo.
   define output parameter shipperid as character no-undo.

   define variable parent_id as character no-undo.
   define buffer abs_mstr_parent for abs_mstr.

   shipperid = "".

   do for abs_mstr_parent:
      for first abs_mstr_parent where
            abs_id          = in_abs_id and
            abs_shipfrom    = in_shipfrom
      no-lock: end.

      do while available abs_mstr_parent and abs_par_id <> "":
         parent_id = abs_par_id.

         for first abs_mstr_parent where
               abs_shipfrom = abs_mstr.abs_shipfrom and
               abs_id = parent_id
         no-lock: end.

         if available (abs_mstr_parent) and
            abs_id begins "s" or
            abs_id begins "p"
         then do:
            leave.
         end.

      end.  /* do while available abs_mstr_parent */

      if abs_id begins "s" or
         abs_id begins "p" then
         shipperid = abs_id.

   end.

END PROCEDURE. /* get_shipper */
